<?php 
require 'Model.php';
class IndexModel extends Model{
	function __construct(){
		parent::__construct();
		$this->mod = 'food';
	}
	function getList(){
		$sql_vt="select * from videotype";
		$vt_list = $this->conn->query($sql_vt);
		//var_dump($vt_list);
		$v_list=array();
		foreach($vt_list as $one){
		    $sql="select * from {$this->mod} where tid=".$one['tid']." order by id  limit 0,6 ";
		   // echo $sql."</br>";
		    $vlist=array();
		    $vlist['typename']=$one['typename'];
		    $vlist['tid']=$one['tid'];
		    $vlist['list']=$this->conn->query($sql);
		    $v_list[]=$vlist;
		}//var_dump($v_list);
		    return $v_list;
	}
	function getVideoType(){
		$sql_vt="select * from videotype";
		$data = $this->conn->query($sql_vt);
		//var_dump($data);
			return $data;
}
	function getVideoByHits(){
	 $sql_hits="select * from {$this->mod} order by id desc limit 0,4";
	 $data = $this->conn->query($sql_hits);
			return $data;
	}
	function getVideoByDowntimes(){
		$sql_downtimes="select * from {$this->mod} order by hittimes desc limit 0,4";
		$data = $this->conn->query($sql_downtimes);
			return $data;

	}
	function getVideoById($id){
		$sql="select * from {$this->mod} where tid=".$id;
	    $data = $this->conn->query($sql);
		return $data;

	}
	function getTypeByTid($id){
		$sql="select typename from videotype where tid={$id}";
	    $data = $this->conn->query($sql);
		return $data;

	}
	function getVideoByVid($id){
		$sql="select * from food where id={$id}";
	    $data = $this->conn->query($sql);
	    $vid_list=array();
		foreach($data as $one){
		    $vlist=array();
		    $vlist['id']=$one['id'];
		    $vlist['name']=$one['name'];
		    $vlist['pic']=$one['pic'];
		    $vlist['yl']=$one['yl'];
		     $vlist['hittimes']=$one['hittimes'];
		    $vlist['zf']=$one['zf'];
		    $vlist['pl']=$one['pl'];
		    $vid_list=$vlist;
				return $vid_list;
		}
	}
	function add($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  				}
			  else{
			  	$pic='';
			  }
			  $user = array(
					'uname' => trim($data['username']),  
					'password' => $data['password'],
					'gender' => $data['gender'],
					'birthdate' => $data['birthdate'],
					'hobby' => implode($data['hobby'], ','),
					'degree' => $data['degree'],
					'intro' => $data['intro'],
					'pic'=>$pic
			  	);
			  $keys = implode(',',array_keys($user));
			  $values = implode("','", array_values($user));
			  $sql="insert into {$this->mod} ({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
		}
}




 ?>